<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'planWriteForm.jsp' starting page</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	<script>

	function formCheck(){
		if( planform.title.value.length == 0){
			alert('제목을 입력해 주세요.');
			planform.title.focus();
			return false;
		}
		if( planform.startyear.value.length == 0){
			alert('시작 년도를 입력해 주세요.');
			planform.startyear.focus();
			return false;
		}
		if( planform.startmonth.value.length == 0){
			alert('시작 월을 입력해 주세요.');
			planform.startmonth.focus();
			return false;
		}
		if( planform.startday.value.length == 0){
			alert('시작 일을 입력해 주세요.');
			planform.startday.focus();
			return false;
		}
		if( planform.endyear.value.length == 0){
			alert('종료 년도를 입력해 주세요.');
			planform.endyear.focus();
			return false;
		}
		if( planform.endmonth.value.length == 0){
			alert('종료 월을 입력해 주세요.');
			planform.endmonth.focus();
			return false;
		}
		if( planform.endday.value.length == 0){
			alert('종료 일을 입력해 주세요.');
			planform.endday.focus();
			return false;
		}

		var syyyy = planform.startyear.value;
		var smm = planform.startmonth.value;
		if( smm < 10 ){
			smm = "0" + smm;
		}
		var sdd = planform.startday.value;
		if( sdd < 10 ){
			sdd = "0" + sdd;
		}
		var shh = planform.starttime.value;
		if( shh < 10 ){
			shh = "0" + shh;
		}

		var eyyyy = planform.endyear.value;
		var emm = planform.endmonth.value;
		if( emm < 10 ){
			emm = "0" + emm;
		}
		var edd = planform.endday.value;
		if( edd < 10 ){
			edd = "0" + edd;
		}
		var ehh = planform.endtime.value;
		if( ehh < 10 ){
			ehh = "0" + ehh;
		}
		var sdate = syyyy + smm + sdd + shh;
		var edate = eyyyy + emm + edd + ehh;

		if( sdate >= edate ){
			alert('종료일은 시작일보다 나중이어야 합니다.');
			return false;
		}

		planform.startdate.value = syyyy + smm + sdd + " " + shh;
		planform.enddate.value = eyyyy + emm + edd + " " + ehh;
	}
	</script>
	<jsp:include page="../index.jsp"></jsp:include>
  </head>

  <body>
    <h4>[ 休暇登録 ]</h4>
    <form name="planform" action="<s:url value="/plan/planWrite.action"/>" method="post" onsubmit="return formCheck();">
    <input type="hidden" name="plan.id" value="${session.loginid}"/>
    <table>
    <tbody>
    <tr>
    	<td align="center" style="width: 100; background-color: efefef;">休暇区分</td>
    	<td><input name="plan.title" id="title" style="width: 330"/></td>
    </tr>
    <tr>
    	<td align="center" style="width: 100; background-color: efefef;">開始日</td>
    	<td align="left">
    	<select name="startyear">
    	<option label="選択"/>
    	<s:iterator var="counter" begin="2013" end="2020">
    	<option value="<s:property value="#counter"/>"><s:property value="#counter"/></option>
    	</s:iterator>
    	</select>年

    	<select name="startmonth">
    	<option label="選択"/>
    	<s:iterator var="counter" begin="1" end="12">
    	<option value="<s:property value="#counter"/>"><s:property value="#counter"/></option>
    	</s:iterator>
    	</select>月

    	<select name="startday">
    	<option label="選択"/>
    	<s:iterator var="counter" begin="1" end="31">
    	<option value="<s:property value="#counter"/>"><s:property value="#counter"/></option>
    	</s:iterator>
    	</select>日



    	<input type="hidden" name="plan.startdate" id="startdate"/>
    	</td>
    </tr>
    <tr>
    	<td align="center" style="width: 100; background-color: efefef;">終了日</td>
    	<td align="left">
    	<select name="endyear">
    	<option label="選択"/>
    	<s:iterator var="counter" begin="2013" end="2020">
    	<option value="<s:property value="#counter"/>"><s:property value="#counter"/></option>
    	</s:iterator>
    	</select>年

    	<select name="endmonth">
    	<option label="選択"/>
    	<s:iterator var="counter" begin="1" end="12">
    	<option value="<s:property value="#counter"/>"><s:property value="#counter"/></option>
    	</s:iterator>
    	</select>月

    	<select name="endday">
    	<option label="選択"/>
    	<s:iterator var="counter" begin="1" end="31">
    	<option value="<s:property value="#counter"/>"><s:property value="#counter"/></option>
    	</s:iterator>
    	</select>日
      	<input type="hidden" name="plan.enddate" id="enddate"/>
    	</td>
    </tr>

    <tr>
    	<td align="center" style="width: 100; background-color: efefef;">休暇事由</td>
    	<td><input name="plan.place" style="width: 330"/></td>
    </tr>
    <tr>
    	<td align="center" style="width: 100; background-color: efefef;">備考</td>
    	<td><textarea name="plan.memo" rows="7" style="width: 350"></textarea></td>
    </tr>
    <tr>
    	<td align="center" colspan="2">
    	<input type="submit" value="登録" style="width: 70"/>
    	<input type="reset" value="戻る" style="width: 70"/>
    	</td>
    </tr>
    </tbody>
    </table>
    </form>

  </body>
</html>
